package huoye.shops.huoye.operation.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import java.util.List;

import butterknife.BindView;
import huoye.shops.R;
import huoye.shops.base.APIUrls;
import huoye.shops.huoye.operation.model.ActivePrizes;
import huoye.shops.huoye.operation.model.PrizeCancelData;
import huoye.shops.huoye.operation.model.UserInfo;
import huoye.shops.utils.StockUtils;
import huoye.shops.widget.RoundImageView;


/**
 * Created by uesr on 2018/8/10.
 */

public class PrizeCancelAdapter extends RecyclerViewAdapter<PrizeCancelAdapter.ViewHolder,PrizeCancelData> {




    public PrizeCancelAdapter(Context context) {
        super(context, R.layout.item_prize_cancel);
    }

    @Override
    protected ViewHolder initViewHolder(View view, int i) {

        return new ViewHolder(view);
    }

    @Override
    protected void bindView(ViewHolder holder, final PrizeCancelData data, int i) {

        UserInfo userInfo = data.getUserInfo();
        ActivePrizes activePrizes = data.getActivePrizes();

        if(getContext() != null){
            Glide.with(getContext())
                    .load(userInfo.getHeadImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvHead);
        }

        if(getContext() != null){
            Glide.with(getContext())
                    .load(APIUrls.COMMON_CONFIG.TYPE_COMMON_ALIYUN+activePrizes.getPrizeImg())
                    .dontAnimate()
                    .placeholder(R.mipmap.ic_wait_logo)
                    .error(R.mipmap.ic_error)
                    .into(holder.rvPrizeImg);
        }

        //核销状态 0-未核销 1-已核销 2-已失效
        if(userInfo.getiState() == 0){
            holder.tvStare.setText("未核销");
            holder.tvStare.setSelected(true);
        }else if(userInfo.getiState() == 1){
            holder.tvStare.setText("已核销"+activePrizes.getUpdateTime());
            holder.tvStare.setSelected(false);
        }else {
            holder.tvStare.setText("已失效");
            holder.tvStare.setSelected(false);
        }

        holder.tvName.setText(userInfo.getNickName());


        holder.tvGoodsTitle.setText(activePrizes.getEtTitle());
        holder.tvGoodsName.setText(activePrizes.getPrizeTitle());
        holder.tvMoeny.setText("￥"+StockUtils.moenyStyleNoZero(activePrizes.getPrice()));
        holder.tvNum.setText("数量："+activePrizes.getPrizeNum());

    }


    public class ViewHolder extends RecyclerViewAdapter.ViewHolder {

        @BindView(R.id.item_prize_cancel_tv_name)
        TextView tvName;
        @BindView(R.id.item_prize_cancel_tv_state)
        TextView tvStare;
        @BindView(R.id.item_prize_cancel_goods_name)
        TextView tvGoodsName;
        @BindView(R.id.item_prize_cancel_goods_title)
        TextView tvGoodsTitle;
        @BindView(R.id.item_prize_cancel_tv_money)
        TextView tvMoeny;
        @BindView(R.id.item_prize_cancel_tv_num)
        TextView tvNum;



        @BindView(R.id.item_prize_cancel_rv_head)
        RoundImageView rvHead ;
        @BindView(R.id.item_prize_cancel_rv_prize_img)
        RoundImageView rvPrizeImg ;



        public ViewHolder(View itemView) {
            super(itemView);
        }
    }




}
